package com.hly.tool.file;

import com.matrixone.apps.framework.ui.UIUtil;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

/**
 * @Auther: Jack.Hao
 * @Date: 2021/4/12 16:55
 * @Description:
 */
public class FileUtil {


    /**
     * @param folder
     * @return void
     * @Author HLY
     * @CreateTime 2023/9/4
     * @Description: 递归删除文件夹
     */
    private void deleteFolder(File folder) {
        if (folder.isDirectory()) {
            File[] files = folder.listFiles();
            if (files != null) {
                for (File file : files) {
                    deleteFolder(file);
                }
            }
        }
        folder.delete();
    }


    /**
     * 处理csv文件
     *
     * @param csvFilePath
     * @param charSet
     * @return
     * @throws Exception
     */
    public static List<List> getCSVFileData(String csvFilePath, String charSet) throws Exception {
        if (charSet == null || charSet.trim().equals("")) {
            charSet = "GB2312";
        }
        String line = "";
        String cvsSplitBy = ",";
        BufferedReader br = null;
        FileInputStream fis = null;
        InputStreamReader isr = null;
        List<List> dataList = new ArrayList<List>();
        try {
            fis = new FileInputStream(csvFilePath);
            isr = new InputStreamReader(fis, charSet);
            br = new BufferedReader(isr);
            while ((line = br.readLine()) != null) {
                String[] country = line.split(cvsSplitBy);
                List<String> rowData = Arrays.asList(country);
                List<String> newRowData = new ArrayList<>();
                for (String str : rowData) {
                    if (UIUtil.isNotNullAndNotEmpty(str) && str.substring(0, 1).contains("\uFEFF")) {
                        str = str.substring(1);
                    }
                    newRowData.add(str);
                }
                dataList.add(newRowData);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (isr != null) {
                    isr.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return dataList;
    }

    /**
     * 读取文件中的数据
     *
     * @param filePath
     * @return
     * @throws Exception
     */
    public static List<String> getFileData2(String filePath) throws Exception {
        String line = "";
        BufferedReader br = null;
        List<String> dataList = new ArrayList<String>();
        try {
            br = new BufferedReader(new FileReader(filePath));
            while ((line = br.readLine()) != null) {
                dataList.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                br.close();
            }
        }

        return dataList;
    }

    /**
     * 读取文件中的数据
     *
     * @param filePath
     * @return
     * @throws Exception
     */
    public static List<List<String>> getFileData2(String filePath, String split) throws Exception {
        String line = "";
        BufferedReader br = null;
        List<List<String>> dataList = new ArrayList<List<String>>();
        try {
            br = new BufferedReader(new FileReader(filePath));
            while ((line = br.readLine()) != null) {
                String[] country = line.split(split);
                List<String> rowData = Arrays.asList(country);
                dataList.add(rowData);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                br.close();
            }
        }

        return dataList;
    }


    /**
     * 获取文件中的数据
     *
     * @param filePath 文件地址
     * @param charSet  编码集
     * @param split    分隔符
     * @return
     * @throws Exception
     */
    public static List<List<String>> getFileData(String filePath, String charSet, String split) throws Exception {

        String line = "";
        BufferedReader br = null;
        FileInputStream fis = null;
        InputStreamReader isr = null;
        List<List<String>> dataList = new ArrayList<List<String>>();
        try {

            fis = new FileInputStream(filePath);
            isr = new InputStreamReader(fis, charSet);
            br = new BufferedReader(isr);
            while ((line = br.readLine()) != null) {
                String[] country = line.split(split);
                List<String> rowData = Arrays.asList(country);
                dataList.add(rowData);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (isr != null) {
                    isr.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return dataList;
    }


    /**
     * @param filePath 文件地址
     * @param filePath
     * @return
     * @throws Exception
     */
    public static List<String> getFileData(String filePath, String charSet) throws Exception {

        String line = "";
        BufferedReader br = null;
        FileInputStream fis = null;
        InputStreamReader isr = null;
        List<String> dataList = new ArrayList<String>();
        try {

            fis = new FileInputStream(filePath);
            isr = new InputStreamReader(fis, charSet);
            br = new BufferedReader(isr);
            while ((line = br.readLine()) != null) {
                dataList.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (isr != null) {
                    isr.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return dataList;
    }


    /**
     * 获取文件中的数据
     *
     * @param filePath
     * @return
     * @throws Exception
     */
    public static List<String> getFileData(String filePath) throws Exception {
        return getFileData(filePath, "UTF-8");
    }


    /**
     * NIO 写入数据到固定路径
     *
     * @param content
     */
    public static void writer(String content) {
        writerToLocal(content, "C:/temp/out.txt", "utf-8");
    }

    /**
     * NIO 写入数据到固定路径
     *
     * @param content
     */
    public static void writerToLocal(String content, String filePath) {
        writerToLocal(content, filePath, "utf-8");
    }

    /**
     * NIO 写入数据到固定路径
     *
     * @param content
     */
    public static void writerToLocal(String content, String filePath, String charset) {
        try {
            byte[] arr = content.getBytes(charset);
            //
            FileOutputStream fout = new FileOutputStream(filePath);
            //
            FileChannel channel = fout.getChannel();
            //
            ByteBuffer buffer = ByteBuffer.allocate(arr.length);
            buffer.put(arr);
            buffer.flip();
            //
            channel.write(buffer);
            //
            buffer.clear();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


    /**
     * NIO 写入数据到指定文件
     *
     * @param message
     */
    public static void writer(String path, String message) {
        FileOutputStream fout = null;
        FileChannel channel = null;
        try {
            byte[] arr = message.getBytes("utf-8");
            //
            fout = new FileOutputStream(path);
            //
            channel = fout.getChannel();
            //
            ByteBuffer buffer = ByteBuffer.allocate(arr.length);
            buffer.put(arr);
            buffer.flip();
            //
            channel.write(buffer);
            //
            buffer.clear();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (fout != null) {
                try {
                    fout.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (channel != null) {
                try {
                    channel.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }


    /**
     * 字节缓存流
     * 使用缓存流复制文件 默认缓存 1024 byte
     *
     * @param srcPath 源文件路径
     * @param target  目标文件路径
     * @return
     * @throws Exception
     */
    public boolean byteCopy(String srcPath, String target) throws Exception {
        return byteCopy(srcPath, target, 1024);
    }


    /**
     * 字节缓存流
     * 使用字节缓存流复制文件 默认缓存 1024 byte
     *
     * @param srcPath  源文件路径
     * @param target   目标文件路径
     * @param byteSize 缓存数组的大小
     * @return
     * @throws Exception
     */
    public boolean byteCopy(String srcPath, String target, int byteSize) throws Exception {
        boolean result = true;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(new File(srcPath));
            fos = new FileOutputStream(new File(target));
            int len = 0;
            byte[] bytes = new byte[byteSize];
            // 一次读取一个字节
            while ((len = fis.read(bytes)) != -1) {
                fos.write(bytes, 0, len);
                fos.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    /**
     * 字符缓冲流
     * 使用字符缓冲流复制文件 默认缓存 1024 byte
     *
     * @param srcPath 源文件路径
     * @param target  目标文件路径
     * @return
     * @throws Exception
     */
    public boolean lineCopy(String srcPath, String target) throws Exception {
        boolean result = true;
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new FileReader(new File(srcPath)));
            bw = new BufferedWriter(new FileWriter(new File(target)));
            String line = "";
            while ((line = br.readLine()) != null) {
                bw.write(line);
                bw.newLine();
                bw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (br != null) {
                br.close();
            }

            if (bw != null) {
                bw.close();
            }

        }
        return result;
    }


    /**
     * 删除文件夹下所有文件 包含子文件夹内容及子文件夹
     * delete file
     *
     * @param path 文件夹路径
     * @return
     */
    public static boolean delAllFile(String path) {
        boolean flag = false;
        File file = new File(path);
        if (!file.exists()) {
            return flag;
        }
        if (!file.isDirectory()) {
            return flag;
        }
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
                temp = new File(path + tempList[i]);
            } else {
                temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
                temp.delete();
            }
            if (temp.isDirectory()) {
                delAllFile(path + "/" + tempList[i]);//
                delFolder(path + "/" + tempList[i]);//
                flag = true;
            }
        }
        return flag;
    }

    /**
     * 删除指定文件夹本身及文件夹下的所有内容
     * delete folder
     *
     * @param folderPath
     */
    public static void delFolder(String folderPath) {
        try {
            delAllFile(folderPath); //
            String filePath = folderPath;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            myFilePath.delete(); //
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取文件夹下所有的文件
     *
     * @param srcFile 文件夹
     * @return
     */
    public static List<File> getAllFiles(File srcFile) {
        List<File> fileList = new ArrayList<File>();
        File[] tmp = srcFile.listFiles();

        for (int i = 0; i < tmp.length; i++) {

            if (tmp[i].isFile()) {
                fileList.add(tmp[i]);
                ////System.out.println("add file: " + tmp[i].getName());
            }

            if (tmp[i].isDirectory()) {
                if (tmp[i].listFiles().length != 0) {//
                    fileList.addAll(getAllFiles(tmp[i]));
                } else {//
                    fileList.add(tmp[i]);
                    ////System.out.println("add empty dir: " + tmp[i].getName());
                }
            }
        }    // end for

        return fileList;
    }

    /**
     * @param srcDir
     * @return
     */
    private static List<File> getAllFiles2(File srcDir) {

        List<File> fileList = new ArrayList<File>();
        File[] tmp = new File[]{srcDir};
        for (int i = 0; i < tmp.length; i++) {
            if (tmp[i].isFile()) {
                fileList.add(tmp[i]);
                ////System.out.println("add file: " + tmp[i].getName());
            }

            if (tmp[i].isDirectory()) {
                if (tmp[i].listFiles().length != 0) {//
                    fileList.addAll(getAllFiles(tmp[i]));
                } else {//
                    fileList.add(tmp[i]);
                    ////System.out.println("add empty dir: " + tmp[i].getName());
                }
            }
        }    // end for

        return fileList;
    }


    /**
     * 当前打包程序会将所选的文件夹里面的内容打包到zip中
     *
     * @param srcPath
     * @param zipFileName
     * @return
     */
    public static boolean zip(String srcPath, String zipFileName) {
        ////System.out.println("zip compressing...");
        int BUFFER = 512;
        File srcFile = new File(srcPath);
        List<File> fileList = getAllFiles(srcFile);//
        byte[] buffer = new byte[BUFFER];//
        ZipEntry zipEntry = null;
        int readLength = 0;//
        ZipOutputStream zipOutputStream = null;
        InputStream inputStream = null;
        try {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFileName));
            for (File file : fileList) {
                if (file.isFile()) {//
                    zipEntry = new ZipEntry(getRelativePath(srcPath, file));
                    zipEntry.setSize(file.length());
                    zipEntry.setTime(file.lastModified());
                    try {
                        zipOutputStream.putNextEntry(zipEntry);
                        inputStream = new BufferedInputStream(new FileInputStream(file));
                        while ((readLength = inputStream.read(buffer, 0, BUFFER)) != -1) {
                            zipOutputStream.write(buffer, 0, readLength);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (inputStream != null) {
                            inputStream.close();
                        }
                    }
                    ////System.out.println("file compressed: " + file.getCanonicalPath());
                } else {//
                    zipEntry = new ZipEntry(getRelativePath(srcPath, file) + "/");
                    zipOutputStream.putNextEntry(zipEntry);
                    ////System.out.println("dir compressed: " + file.getCanonicalPath() + "/");
                }
            }    // end for
        } catch (FileNotFoundException e) {
            ////System.out.println(e.getMessage());
            e.printStackTrace();
            ////System.out.println("zip fail!");
            return false;
        } catch (Exception e) {
            ////System.out.println(e.getMessage());
            e.printStackTrace();
            ////System.out.println("zip fail!");
            return false;
        } finally {
            try {
                zipOutputStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        ////System.out.println("zip success!");
        return true;
    }

    /**
     * 当前打包程序会将所选的文件夹打包到zip中
     *
     * @param srcPath
     * @param zipFileName
     * @return
     */
    public static boolean zip2(String srcPath, String zipFileName) {
        ////System.out.println("zip compressing...");
        int BUFFER = 512;
        File srcFile = new File(srcPath);
        String name = srcFile.getName();
        List<File> fileList = getAllFiles2(srcFile);//
//        //System.out.println(fileList);
        byte[] buffer = new byte[BUFFER];//
        ZipEntry zipEntry = null;
        int readLength = 0;//
        ZipOutputStream zipOutputStream = null;
        InputStream inputStream = null;
        try {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFileName));
//            zipEntry = new ZipEntry(getRelativePath(srcFile.getParent(), srcFile) + "/");
//            zipOutputStream.putNextEntry(zipEntry);
            String parent = srcFile.getParent();
            fileList.add(0, srcFile);
            for (File file : fileList) {
                if (file.isFile()) {//
                    zipEntry = new ZipEntry(getRelativePath(parent, file));
                    zipEntry.setSize(file.length());
                    zipEntry.setTime(file.lastModified());
                    try {
                        zipOutputStream.putNextEntry(zipEntry);
                        inputStream = new BufferedInputStream(new FileInputStream(file));
                        while ((readLength = inputStream.read(buffer, 0, BUFFER)) != -1) {
                            zipOutputStream.write(buffer, 0, readLength);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (inputStream != null) {
                            inputStream.close();
                        }
                    }
                    ////System.out.println("file compressed: " + file.getCanonicalPath());
                } else {//
                    zipEntry = new ZipEntry(getRelativePath(parent, file) + "/");
                    zipOutputStream.putNextEntry(zipEntry);
                    ////System.out.println("dir compressed: " + file.getCanonicalPath() + "/");
                }
            }    // end for
        } catch (FileNotFoundException e) {
            ////System.out.println(e.getMessage());
            e.printStackTrace();
            ////System.out.println("zip fail!");
            return false;
        } catch (Exception e) {
            ////System.out.println(e.getMessage());
            e.printStackTrace();
            ////System.out.println("zip fail!");
            return false;
        } finally {
            try {
                zipOutputStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        ////System.out.println("zip success!");
        return true;
    }


    /**
     * @Description: 生成带目录的文件压缩包
     * @author: luog
     * @Date: 2021/1/20
     * @param: srcDir 源文件路径
     * @param: outDir 最终文件名
     * @param: KeepDirStructure
     * @returns: void
     */
    public static boolean zipWithDir(String srcPath, String zipPath) {
        int BUFFER_SIZE = 512;
        byte[] buf = new byte[BUFFER_SIZE];
        try {
            File sourceFile = new File(srcPath);
            String srcName = sourceFile.getName();
            ZipOutputStream zos = null;
            OutputStream out = new FileOutputStream(new File(zipPath));

            zos = new ZipOutputStream(out);
            zos.putNextEntry(new ZipEntry(srcName + File.separator + sourceFile.getName()));
            int len;
            FileInputStream in = new FileInputStream(sourceFile);
            while ((len = in.read(buf)) != -1) {
                zos.write(buf, 0, len);
            }
            zos.closeEntry();

            zos.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * @param dirPath
     * @param file
     * @return
     */
    private static String getRelativePath(String dirPath, File file) {
        File dir = new File(dirPath);
        String relativePath = file.getName();

        while (true) {
            file = file.getParentFile();

            if (file == null) {
                break;
            }

            if (file.equals(dir)) {
                break;
            } else {
                relativePath = file.getName() + "/" + relativePath;
            }
        }    // end while

        return relativePath;
    }


    /**
     * \     * @param is
     *
     * @param os
     * @return
     */
    public static boolean inputStreamCopyToOutputStream(InputStream is, OutputStream os) {
        int BUFFER_SIZE = 4096;
        final byte[] buffer = new byte[BUFFER_SIZE];
        try {
            int count;
            while ((count = is.read(buffer)) != -1) {
                os.write(buffer, 0, count);
            }
            os.flush();
        } catch (Exception e) {
            return false;
        }
        return true;
    }


    /**
     * @param zipPath
     * @param descDir
     */
    public static void unzip(String zipPath, String descDir) throws IOException {
        unzip(new File(zipPath), descDir);
    }

    /**
     * @param zipFile
     * @param descDir
     */
    @SuppressWarnings("rawtypes")
    public static void unzip(File zipFile, String descDir) throws IOException {
        ZipFile zip = null;
        try {
            zip = new ZipFile(zipFile, Charset.forName("GBK"));//
//        String name = zip.getName().substring(zip.getName().lastIndexOf('\\') + 1, zip.getName().lastIndexOf('.'));
            File pathFile = new File(descDir);
            if (!pathFile.exists()) {
                pathFile.mkdirs();
            }
            for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements(); ) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                String zipEntryName = entry.getName();
                InputStream in = zip.getInputStream(entry);
                String outPath = (descDir + "/" + zipEntryName).replaceAll("\\*", "/");
                //
                File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
                if (!file.exists()) {
                    file.mkdirs();
                }
                //
                if (new File(outPath).isDirectory()) {
                    continue;
                }
                //
                FileOutputStream out = new FileOutputStream(outPath);
                byte[] buf1 = new byte[1024];
                int len;
                try {
                    while ((len = in.read(buf1)) > 0) {
                        out.write(buf1, 0, len);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    in.close();
                    out.close();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (zip != null) {
                try {
                    zip.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            zip.close();

        }
        return;
    }


    /**
     * 给一个文件追加内容
     *
     * @param filePath
     * @param content
     */
    public static void addContent(String filePath, String content) {
        addContent(filePath, content, "utf-8");
    }


    /**
     * 给一个文件追加内容
     *
     * @param file
     * @param content
     */
    public static void addContent(File file, String content) {
        addContent(file, content, "utf-8");
    }

    /**
     * 给一个日志文件追加内容
     *
     * @param file
     * @param content
     */
    public static void addLogContent(File file, String content) {
        addLogContent(file, content, "utf-8");
    }


    /**
     * 给一个日志文件追加内容
     *
     * @param filePath
     * @param content
     */
    public static void addLogContent(String filePath, String content) {
        addLogContent(filePath, content, "utf-8");
    }


    /**
     * 给一个文件追加内容
     *
     * @param filePath
     * @param content
     */
    public static void addContent(String filePath, String content, String charset) {
        File file = new File(filePath);
        FileOutputStream fos = null;
        OutputStreamWriter osw = null;
        try {
            if (!file.exists())//不存在就新建
            {
                String parentPath = file.getParent();
                File parentDir = new File(parentPath);
                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }
                file.createNewFile();
                fos = new FileOutputStream(file);
            } else //存在就读取
            {
                fos = new FileOutputStream(file, true);
            }
            osw = new OutputStreamWriter(fos, charset);
            osw.write(content); //写入内容
            osw.write("\r\n");  //换行
        } catch (Exception e) {
            e.printStackTrace();
        } finally {   //关闭流
            try {
                if (osw != null) {
                    osw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    /**
     * 给一个文件追加内容
     *
     * @param file
     * @param content
     */
    public static void addContent(File file, String content, String charset) {
        FileOutputStream fos = null;
        OutputStreamWriter osw = null;
        try {
            if (!file.exists())//不存在就新建
            {
                String parentPath = file.getParent();
                File parentDir = new File(parentPath);
                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }
                file.createNewFile();
                fos = new FileOutputStream(file);
            } else //存在就读取
            {
                fos = new FileOutputStream(file, true);
            }
            osw = new OutputStreamWriter(fos, charset);
            osw.write(content); //写入内容
            osw.write("\r\n");  //换行
        } catch (Exception e) {
            e.printStackTrace();
        } finally {   //关闭流
            try {
                if (osw != null) {
                    osw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    /**
     * 给一个日志文件追加内容
     *
     * @param file
     * @param content
     * @param charset
     */
    public static void addLogContent(File file, String content, String charset) {
        FileOutputStream fos = null;
        OutputStreamWriter osw = null;
        try {
            if (!file.exists())//不存在就新建
            {
                String parentPath = file.getParent();
                File parentDir = new File(parentPath);
                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }
                file.createNewFile();
                fos = new FileOutputStream(file);
            } else //存在就读取
            {
                fos = new FileOutputStream(file, true);
            }

            content = getCurrentTime() + "    " + content;
            osw = new OutputStreamWriter(fos, charset);
            osw.write(content); //写入内容
            osw.write("\r\n");  //换行
        } catch (Exception e) {
            e.printStackTrace();
        } finally {   //关闭流
            try {
                if (osw != null) {
                    osw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    /**
     * 给一个日志文件追加内容
     *
     * @param filePath
     * @param content
     * @param charset
     */
    public static void addLogContent(String filePath, String content, String charset) {
        addLogContent(new File(filePath), content, charset);
    }


    /**
     * @return
     */
    public static String getCurrentTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        Date date = new Date();
        return sdf.format(date);
    }


    public static void main(String[] args) {
        FileUtil.zip2("D:\\FTP\\userBehavior\\SFDPKG_prd-40535902-00004476A.1", "D:\\FTP\\userBehavior\\ToTC\\88.zip");

    }


}
